package com.sqfw.project.wpReport.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.sqfw.framework.web.page.PageDomain;
import com.sqfw.framework.web.page.TableSupport;
import com.sqfw.project.wpReport.domain.SeatEvaluateReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.project.wpReport.domain.ScidTypeReport;
import com.sqfw.project.wpReport.service.IScidTypeReportService;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.common.utils.poi.ExcelUtil;
import com.sqfw.framework.web.page.TableDataInfo;

/**
 * 坐席工作量汇总表Controller
 * 
 * @author lx
 * @date 2023-07-27
 */
@RestController
@RequestMapping("/wpReport/scidTypeReport")
public class ScidTypeReportController extends BaseController
{
    @Autowired
    private IScidTypeReportService scidTypeReportService;

    /**
     * 查询坐席工作量汇总表列表
     */
    @PreAuthorize("@ss.hasPermi('getScidTypeReportList')")
    @GetMapping("/getScidTypeReportList")
    public TableDataInfo getScidTypeReportList(ScidTypeReport scidTypeReport) {
        long a = System.currentTimeMillis();
//        startPage();
        TableDataInfo list1 = scidTypeReportService.getScidTypeReportList(scidTypeReport);
        List<ScidTypeReport> list = (List<ScidTypeReport>) list1.getRows();
        long total = list1.getTotal();
//        PageDomain pageDomain = TableSupport.buildPageRequest();
//        Integer pageNum = pageDomain.getPageNum();
//        Integer pageSize = pageDomain.getPageSize();
        logger.info("第一个sql: {}", System.currentTimeMillis() - a);
        if (total > 0) {
//            TableDataInfo rows = scidTypeReportService.getScidTypeReportList(scidTypeReport);
//            List<ScidTypeReport> reportList = (List<ScidTypeReport>) rows.getRows();
            List<ScidTypeReport> reportList = (List<ScidTypeReport>) list1.getRows();
            ScidTypeReport report = new ScidTypeReport();
            report.setCode("总计");
            //弹屏建单
            int screenCount = reportList.stream()
                    .map(ScidTypeReport::getScreenCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setScreenCount(screenCount);
            //12345工单
            int wpCount = reportList.stream()
                    .map(ScidTypeReport::getWpCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setWpCount(wpCount);
          /*  //自办量
            int selfCount = reportList.stream()
                    .map(ScidTypeReport::getSelfCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSelfCount(selfCount);*/
            //手工建单
            int manualCount = reportList.stream()
                    .map(ScidTypeReport::getManualCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setManualCount(manualCount);

            //110接警
            int alarmCount = reportList.stream()
                    .map(ScidTypeReport::getAlarmCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setAlarmCount(alarmCount);

            //一网通办系统
            int networkCount = reportList.stream()
                    .map(ScidTypeReport::getNetworkCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setNetworkCount(networkCount);

            //在线帮办
            int onlineCount = reportList.stream()
                    .map(ScidTypeReport::getOnlineCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setOnlineCount(onlineCount);

            //专项整治
            int specialCount = reportList.stream()
                    .map(ScidTypeReport::getSpecialCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSpecialCount(specialCount);

            //白事热线
            int funeralCount = reportList.stream()
                    .map(ScidTypeReport::getFuneralCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setFuneralCount(funeralCount);

            //12345信息单
            int informationCount = reportList.stream()
                    .map(ScidTypeReport::getInformationCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setInformationCount(informationCount);

            //政务回访量
            int visitCount = reportList.stream()
                    .map(ScidTypeReport::getVisitCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setVisitCount(visitCount);

            //总计
            int totalCount = reportList.stream()
                    .map(ScidTypeReport::getTotalCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setTotalCount(totalCount);
            list.add(report);

        }

        return list1;

    }

    /**
     * 导出坐席工作量汇总表列表
     */
    @Log(title = "坐席工作量汇总表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('getScidTypeReportList:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScidTypeReport scidTypeReport)
    {
        TableDataInfo info = scidTypeReportService.getScidTypeReportList(scidTypeReport);
        List<ScidTypeReport> list = (List<ScidTypeReport>) info.getRows();

        if (list.size()>0){
            ScidTypeReport report = new ScidTypeReport();

            report.setCode("总计");
            //弹屏建单
            int screenCount = list.stream()
                    .map(ScidTypeReport::getScreenCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setScreenCount(screenCount);
            //12345工单
            int wpCount = list.stream()
                    .map(ScidTypeReport::getWpCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setWpCount(wpCount);
            /*//自办量
            int selfCount = list.stream()
                    .map(ScidTypeReport::getSelfCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSelfCount(selfCount);*/
            //手工建单
            int manualCount = list.stream()
                    .map(ScidTypeReport::getManualCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setManualCount(manualCount);

            //110接警
            int alarmCount = list.stream()
                    .map(ScidTypeReport::getAlarmCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setAlarmCount(alarmCount);

            //一网通办系统
            int networkCount = list.stream()
                    .map(ScidTypeReport::getNetworkCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setNetworkCount(networkCount);

            //在线帮办
            int onlineCount = list.stream()
                    .map(ScidTypeReport::getOnlineCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setOnlineCount(onlineCount);

            // 专项整治
            int specialCount = list.stream()
                    .map(ScidTypeReport::getSpecialCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSpecialCount(specialCount);

            //政务回访量
            int visitCount = list.stream()
                    .map(ScidTypeReport::getVisitCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setVisitCount(visitCount);

            //总计
            int totalCount = list.stream()
                    .map(ScidTypeReport::getTotalCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setTotalCount(totalCount);

            list.add(report);
        }
        ExcelUtil<ScidTypeReport> util = new ExcelUtil<ScidTypeReport>(ScidTypeReport.class);
        util.exportExcel(response, list, "坐席工作量汇总表数据");
    }


}
